package day05;

import java.util.Scanner;

public class Addition {
    static int sum;
    static boolean on = true;

    public static void main(String[] args) throws InterruptedException {
        int score = 0;
        int num1;
        int num2;
        for (int i = 1; i <= 10; i++) {
            num1 = (int) (Math.random() * 100 + 1);
            num2 = (int) (Math.random() * 100 + 1);
            sum = num1 + num2;
            System.out.println("(" + i + ")" + num1 + "+" + num2 + "=");
            int an = 0;
            boolean loop = true;
            do {
                Scanner scanner = new Scanner(System.in);
                try {
                    System.out.println("请输入你的答案");
                    an = scanner.nextInt();
                    loop = false;
                } catch (Exception e) {
                    System.out.println("输入有误，重新输入，需要输入整数");
                }
            } while (loop);
            if (an == -1) {
                break;
            }
            if (an == sum) {
                System.out.println("恭喜你，答对了");
                score += 10;
            } else {
                System.out.println("你答错了.....");
                System.out.println("是否显示答案y/n....");
                on = true;
                int j = 5;
                while (on) {
                    System.out.println(j + "秒后自动退出....");
                    Thread.sleep(1000);
                    j--;
                    if (j == 0) {
                        on = false;
                    }
                }

            }
        }
        System.out.println("总分为" + score);
    }
}
